package it.sd.pwframework.business.bean;

import java.util.ArrayList;
import java.util.HashMap;

public class PwValues extends HashMap<String, Object> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		put("id", id);
		this.id = id;
	}
	
	private StringBuffer labelSearch = new StringBuffer();
	
	public String getLabelSearch() {
		return labelSearch.toString();
	}


	@Override
	public Object put(String key, Object value) {
		
		if ((value!=null) && (value instanceof ArrayList)) {
			ArrayList<PwValues> lista = new ArrayList<PwValues>();
			for (PwValues o : (ArrayList<PwValues>)value) {
				if (!lista.contains(o)) lista.add(o);
			}
			return super.put(key, lista);
		} else {
			return super.put(key, value);
		}
		
	}

	public Object put(String key, Object value, boolean searcheable) {
		Object o = put(key, value);
		
		if (searcheable) {
			if (value!=null) {
				if (labelSearch.length()>0) labelSearch.append(" ");
				labelSearch.append(value.toString());
			}
		}
		
		return o;
	}

	@Override
	public Object get(Object key) {
		if ("labelSearch".equals(key)){
			return labelSearch.toString();
		} else {
			return super.get(key);
		}
	}
	
	
}
